package com.woniu.springboot.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.woniu.springboot.dao.ClazzDao;
import com.woniu.springboot.entity.Clazz;

@Repository
public class ClazzDaoImpl implements ClazzDao{
	@PersistenceContext
	private EntityManager entityManager;
	
	@Override
	public void insertClazz(Clazz clazz) {
		entityManager.persist(clazz);
//		entityManager.
	}

	@Override
	public List<Clazz> selecttClazzs() {
		String hql="from clazz";
		return (List<Clazz>) entityManager.createQuery(hql).getResultList();
	}

	@Override
	public Clazz selectClazzBySid(Integer cid) {
		return entityManager.find(Clazz.class, cid);
	}

	@Override
	public void deleteClazzByCid(Integer cid) {
		Clazz clazz = selectClazzBySid(cid);
		entityManager.remove(clazz);
		
	}

	@Override
	public void updateClazzByCid(Clazz clazz) {
		Clazz claz = selectClazzBySid(clazz.getCid());
		claz.setCname(clazz.getCname());
		entityManager.flush();
	}

}
